home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / progsrc / 3d_2 / sinetabl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-18  |  1.4 KB  |  51 lines

  1. // Routine for a sine and cosine of an angle lookup table
  2. // Angles stored as values between 0 and 32767
  3. // Date 18/12/94
  4.  
  5. #define INTEGER_UNIT 3.051851e-5
  6.  
  7. signed int float_sin[] = { 0,572,1144,1715,2286,2856,3425,3993,
  8. 4560,5126,5690,6252,6813,7371,7927,8481,9032,9580,10126,
  9. 10668,11207,11743,12275,12803,13328,13848,14364,14876,
  10. 15383,15886,16384,16876,17364,17846,18323,18794,19260,
  11. 19720,20173,20621,21062,21497,21925,22347,22762,23170,
  12. 23571,23964,24351,24730,25101,25465,25821,26169,26509,
  13. 26841,27165,27481,27788,28087,28377,28659,28932,29196,
  14. 29451,29697,29934,30162,30381,30591,30791,30982,31163,
  15. 31335,31498,31650,31794,31927,32051,32165,32269,32364,
  16. 32448,32523,32588,32642,32687,32722,32747,32762,32767 };
  17.  
  18.  
  19. // prototypes
  20. //float f_cos(int degree);
  21. //float f_sin(int degree);
  22.  
  23.  
  24.  
  25. // find the sine of an angle
  26. float f_sin(int degree)
  27. {
  28.  degree %= 360;
  29.  
  30.  if (degree>=0 && degree <=90)
  31.    return (float_sin[degree] * INTEGER_UNIT);
  32.  if (degree>90 && degree <=180)
  33.    return (float_sin[(180-degree)] * INTEGER_UNIT);
  34.  if (degree>180 && degree <=270)
  35.    return -(float_sin[(degree-180)] * INTEGER_UNIT);
  36.  else
  37.    return -(float_sin[(360-degree)] * INTEGER_UNIT);
  38. }
  39.  
  40. // find the cosine of an angle
  41. float f_cos(int degree)
  42. {
  43.  degree %= 360;
  44.  
  45.  if (degree>=0 && degree <=270)
  46.    return f_sin(degree+90);
  47.  else
  48.    return f_sin(degree-270);
  49. }
  50.  
  51.